package com.egg.ylt.presenter.impl;

import com.egg.ylt.Utils.API;
import com.egg.ylt.pojo.LoginEntity;
import com.egg.ylt.presenter.IImportCodePresenter;
import com.egg.ylt.view.IImportCodeView;
import com.yonyou.framework.library.bean.ErrorBean;
import com.yonyou.framework.library.common.CommonUtils;
import com.yonyou.framework.library.mvp.impl.BasePresenter;
import com.yonyou.framework.library.net.ReqCallBack;
import com.yonyou.framework.library.net.RequestManager;

import java.util.HashMap;

/**
 * Created by sichaoqi on 2018/9/6.
 */

public class ImportCodePresenterImpl extends BasePresenter<IImportCodeView> implements IImportCodePresenter {
    @Override
    public void getCode(String phone) {
        mView.showDialogLoading("数据加载中");
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("phone", phone);
        RequestManager.getInstance().requestPostByAsyn(API.GET_PHONE_CODE, hashMap, new ReqCallBack<String>() {

            @Override
            public void onReqSuccess(String result) {
                mView.dismissDialogLoading();
                mView.getCode();
            }

            @Override
            public void onFailure(String result) {
                mView.dismissDialogLoading();
//                mView.showError(result);
                CommonUtils.makeEventToast(mContext, result, false);
            }

            @Override
            public void onReqFailed(ErrorBean error) {
                mView.dismissDialogLoading();
//                mView.showException(error.toString());
                CommonUtils.makeEventToast(mContext, error.getMsg(), false);
            }
        });
    }

    @Override
    public void setLogin(String phone, String companyId, String verificationCode) {
        mView.showDialogLoading("数据加载中");
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("phone", phone);
        hashMap.put("companyId", companyId);
        hashMap.put("verificationCode", verificationCode);

        RequestManager.getInstance().requestPostByAsyn(API.GET_LOGIN, hashMap, new ReqCallBack<LoginEntity>() {

            @Override
            public void onReqSuccess(LoginEntity result) {
                mView.dismissDialogLoading();
                mView.onLoginSucceed(result);
            }

            @Override
            public void onFailure(String result) {
                mView.dismissDialogLoading();
//                mView.showError(result);
                CommonUtils.makeEventToast(mContext, result, false);
            }

            @Override
            public void onReqFailed(ErrorBean error) {
                mView.dismissDialogLoading();
//                mView.showException(error.toString());
                mView.onPasswrdError();
                CommonUtils.makeEventToast(mContext, error.getMsg(), false);
            }
        });
    }
}
